package com.itheima.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class JDBCUtils {

	public static Connection connection;

	static {
		Properties prop = new Properties();
		try {
			String path = JDBCUtils.class.getClassLoader().getResource("druid.properties").getPath();
			prop.load(new FileInputStream(path));
			DataSource dataSource = DruidDataSourceFactory.createDataSource(prop);
			connection = dataSource.getConnection();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection(){
        return connection;
    } 
}
